<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>PromiseV3</title>
    <script src="PromiseV3.js"></script>
    <script src="手写promise.js"></script>
</head>
<body>
<script>
    const p = new PromiseV3((resolve, reject) => {
        resolve('daaaa')
    })
    const aaa = new PromiseV3(()=>{})
    const bbb = new PromiseV3('aaa')
    PromiseV3.resolve('hahha').then(data => {
        console.log(data)
    })

    const p1 = new Promise(((resolve, reject) => {
        resolve('p1')
    }))
    const p2 = new Promise(((resolve, reject) => {
        resolve('p2')
    }))

    Promise.all([p1, p2]).then(data =>{
        // 如果全部都是resolve，那么输出的就是resolve的所有数据
        console.log(data)
    }, reason => {
        // 如果又一个reject， 那么输出的就是reject的一个reason
        console.log(reason)
    })

    const p3= new PromiseV3(((resolve, reject) => {
        resolve('p3')
    }))
    const p4 = new PromiseV3(((resolve, reject) => {
        resolve('p4')
    }))

    PromiseV3.all([p3, p4]).then(data =>{
        // 如果全部都是resolve，那么输出的就是resolve的所有数据
        console.log(data)
    }, reason => {
        // 如果又一个reject， 那么输出的就是reject的一个reason
        console.log(reason)
    })


    const p5 = new PromiseV3((resolve,reject) => {
        setTimeout(() => {
            resolve('hhh')
        }, 2000)
    })
    const p6 = new PromiseV3((resolve,reject) => {
        setTimeout(() => {
            reject('fff')
        }, 3000)
    })
    PromiseV3.race([p5, p6]).then(data =>{
        console.log(data)
    },reason => {
        console.log(reason)
    })
</script>

</body>
</html>
